<?php
/**
 * Created by IntelliJ IDEA.
 * User: HXL
 * Date: 2018/6/28
 * Time: 10:18
 */
namespace app\order\model;

use think\Db;
class Fittings extends BaseModel{
    protected $tableName = 'ari_fittings';

    public function search($where){
        $search = Db::table($this->tableName)->where($where)->select();
        return $search;
    }

    /**
     * 联合查询
     * @return \think\paginator\Collection
     */
    public function join($where){
        $num = 10;
        $join = array(
            ['ari_product_principles princ', $this->tableName.'.pid = princ.pid']
        );
        $count = Db::table($this->tableName)->join($join)->where($where)->count();
        $result = Db::table($this->tableName)->join($join)->where($where)
            ->paginate($num, $count, ['query' => request()->param()]);
        return $result;
    }

    public function searchLike($search){
        $count = Db::table($this->tableName)->where('pid', 'like', "%$search%")
            ->whereOr('fid', 'like', "%$search%")
            ->whereOr('fitting', 'like', "%$search%")
            ->count();
        $fittings = Db::table($this->tableName)->where('pid', 'like', "%$search%")
            ->whereOr('fid', 'like', "%$search%")
            ->whereOr('fitting', 'like', "%$search%")
            ->paginate(10, $count, ['query' => request()->param()]);
        return $fittings;
    }
}